#include <vec3f.hpp>
#include "FileHelpers.h"
#include "DisplayObject.h"
#include <fstream>
#include <string>
#include <vector>



using std::ifstream;
using std::ios;
using std::string;

class EATLevel
{
public:
	void render()
	{
		for( size_t i=0; i<displayObjects.size(); i++)
		{
			displayObjects[i].render();

			
		}

	}


	bool load()
	{
		char* levelFile = "level0.eat";
		ifstream inpFile(levelFile, ios::binary );
		if( !inpFile )
		{
			printf("Failed to load eat file: %s\n" , levelFile);
			return false;
		}

		char header[4];
		inpFile.read( header, 4*sizeof(char) );
		printf("Header: %s\n" , header);


		if( "eat" != string(header) )
		{
			printf("not valid eat file\n");
			return false;
		}else{
			
			unsigned int numObjects = readUint( inpFile );
			size_t objsLoaded = 0;
			while ( inpFile.good() && objsLoaded < numObjects )
			{
				DisplayObject dispObj;
				dispObj.load( inpFile );
				displayObjects.push_back( dispObj );


				objsLoaded++;
			}


			printf("success!\n");

			return true;
		}

	}
public:
	std::vector< Vec3f > verts;
	std::vector< int > indices;

	std::vector< DisplayObject > displayObjects;

	

};